//
//  MyorderTVC.m
//  LoveFreshBeen
//
//  Created by vinsent on 16/10/16.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "MyorderTVC.h"
#import "MyorderViewModel.h"
#import "OrderViewModel.h"
#import "MyOrderCell.h"
#import "OrderDescViewController.h"
#import "StatusTVC.h"
#import <SVProgressHUD.h>
#import "OrderdescTVC.h"

@interface MyorderTVC ()
@property(nonatomic,strong) MyorderViewModel *myorderVM;
@property(nonatomic,strong) UIView *placeV;
@end

static NSString *reuseId = @"myorderCellId";
@implementation MyorderTVC


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.rowHeight = 160;
    
    UIView *placeView = [[UIView alloc] initWithFrame:self.view.bounds];
    self.placeV = placeView;
    [self.view addSubview:placeView];
    placeView.backgroundColor = [UIColor lightGrayColor];
    [self loadData];
}

- (void)loadData {
    self.myorderVM = [MyorderViewModel sharedMyorder];
    [self.myorderVM loadMyorderDataWithFinished:^(BOOL succes) {
        if (succes) {
            [self.placeV removeFromSuperview];
            [self.tableView reloadData];
        } else {
            
        }
    }];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _myorderVM.myorders.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    OrderViewModel *orderVM = self.myorderVM.myorders[indexPath.section];
    
    MyOrderCell *cell = [[NSBundle mainBundle] loadNibNamed:@"MyOrderCell" owner:nil options:nil].lastObject;
    
    cell.orderViewM = orderVM;
    
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    StatusTVC *statusTvc = [[StatusTVC alloc] init];
//    [self.navigationController pushViewController:statusTvc animated:YES];
//    OrderViewModel *orderVM = self.myorderVM.myorders[indexPath.section];
//    statusTvc.statusVModel.statuses = orderVM.myorderModel.status_timeline;
    
    
//    OrderdescTVC *desc = [[OrderdescTVC alloc] initWithStyle:UITableViewStyleGrouped];
//    [self.navigationController pushViewController:desc animated:YES];
//    
//    desc.orderVModel = self.myorderVM.myorders[indexPath.section];
//    desc.index = indexPath.section;
    
    OrderDescViewController *vc = [[OrderDescViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
    vc.index = indexPath.section;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

@end
